#the following script makes the relevant conflict maps in the Supplemental Appendix
#it utilizes the following file: ACLED_for_map.csv

#set options
options(stringsAsFactors = F)         # no automatic data transformation
options("scipen" = 100, "digits" = 4) # suppress math annotation
op <- options(gvis.plot.tag='chart')  # set gViz options

#load libraries
library(devtools)
library(OpenStreetMap)
library(DT)
library(RColorBrewer)
library(mapproj)
library(sf)
library(RgoogleMaps)
library(scales)
library(rworldmap)
library(maps)
library(tidyverse)
library(rnaturalearth)
library(rnaturalearthdata)
library(rgeos)
library(ggspatial)
library(maptools)
library(leaflet)
library(sf)
library(tmap)
library(here)
library(rgdal)
library(scales)
devtools::install_github("dkahle/ggmap", ref = "tidyup")

#set seed
set.seed(10)

#read-in data
acleddata <- read.csv("ACLED_for_map.csv")

#format data for mapping
acleddata$fatalities<-acleddata$fatalities+1
acleddatapre<-subset(acleddata, (acleddata$year==2018) | (acleddata$year==2019 & acleddata$month<3) | (acleddata$year==2019 & acleddata$month==3 & acleddata$day<14))
acleddatapost<-subset(acleddata, (acleddata$year==2020) | (acleddata$year==2019 & acleddata$month>3) | (acleddata$year==2019 & acleddata$month==3 & acleddata$day>=14))


#get map
mozambique <- getMap(resolution = "low")

#setup plotting space
par(mfrow=c(1,2))
par(mar=c(.5,1,1.2,.5))

#implement background plot (left)
plot(mozambique, xlim =c(35, 39), ylim =   c(-32.5, -10), 
     asp = 1, bg = "azure1", border = "black", 
     col = "wheat2", fill = T,main="Pre-Cyclone",cex.main=.8)
#add points to map
points(acleddatapre$longitude, acleddatapre$latitude,
       # define colors as transparent
       col = rgb(red = 0, green = 0, blue = 1, alpha = 0.3),
       # define size as number of flights div. by 50
       cex = acleddatapre$fatalities/10, pch = 20)
par(new=FALSE)
#Implement background plot (right)
par(mar=c(.5,.5,1.2,1))
plot(mozambique, xlim =c(35, 39), ylim =   c(-32.5, -10), 
     asp = 1, bg = "azure1", border = "black", 
     col = "wheat2", fill = T,main="Post-Cyclone",cex.main=.8)
#add points to map
points(acleddatapost$longitude, acleddatapost$latitude,
       # define colors as transparen
       col = rgb(red = 0, green = 0, blue = 1, alpha = 0.3),
       # define size as number of flights div. by 50
       cex = acleddatapost$fatalities/10, pch = 20)
